package com.mercury.rabbitmq.config;

import com.mercury.rabbitmq.manager.RabbitMqManager;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Rabbit配置类
 * direct直连模型
 * fanout无路由模式，使用场景广播消息
 * topic 模糊路由模式，适用业务分组
 * fanout > direct > topic 这里是多消费模式，topic和fanout都能实现，通过性能对比选择fanout  11 > 10 > 6
 *
 * @author mercury
 */
@Configuration
public class RabbitMqAutoConfiguration {

    /**
     * 初始化相关配置
     */
    @Bean
    @ConditionalOnProperty(
            name = {"spring.rabbitmq.enabled"},
            havingValue = "true"
    )
    public RabbitMqMessageTemplateConfig rabbitMqMessageTemplateConfig() {
        return new RabbitMqMessageTemplateConfig();
    }


    @Bean
    @ConditionalOnProperty(
            name = {"spring.rabbitmq.enabled"},
            havingValue = "true"
    )
    public RabbitMqManager rabbitMqManager() {
        return new RabbitMqManager();
    }


}